// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_REP_REGISTER_ITEM
// * CreateDate    : 2011-12-26 11:08:53
// * Creater       : CodeSmith
// * LastChangeDate: 2011-12-26 11:08:53
// * LastChanger   : 2011-12-26 11:08:53
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESOL.Common.Entity;
using Suzsoft.Smart.Data;
using System.Data;
using ESOL.Common;

namespace ESOL.Business.Rep
{
/// <summary>
    /// RepRegisterItem
    /// </summary>
    public partial class RepRegisterItemBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objRepRegisterItemEntity">Entity</param>
        /// <returns>Entity</returns>
        public static RepRegisterItemEntity GetRepRegisterItem(RepRegisterItemEntity objRepRegisterItemEntity)
        {
            return DataAccess.SelectSingle<RepRegisterItemEntity>(objRepRegisterItemEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objRepRegisterItemEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertRepRegisterItem(RepRegisterItemEntity objRepRegisterItemEntity)
        {
            return DataAccess.Insert(objRepRegisterItemEntity);
        }

        public static bool InsertRepRegisterItem(List<RepRegisterItemEntity> objRepRegisterItemEntityList)
        {
            return DataAccess.Insert(objRepRegisterItemEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objRepRegisterItemEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateRepRegisterItem(RepRegisterItemEntity objRepRegisterItemEntity)
        {
            return DataAccess.Update(objRepRegisterItemEntity);
        }

        public static bool UpdateRepRegisterItem(List<RepRegisterItemEntity> objRepRegisterItemEntityList)
        {
            return DataAccess.Update<RepRegisterItemEntity>(objRepRegisterItemEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objRepRegisterItemEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteRepRegisterItem(RepRegisterItemEntity objRepRegisterItemEntity)
        {
            return DataAccess.Delete(objRepRegisterItemEntity);
        }

        public static bool DeleteRepRegisterItem(List<RepRegisterItemEntity> objRepRegisterItemEntityList)
        {
            return DataAccess.Delete<RepRegisterItemEntity>(objRepRegisterItemEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetRepRegisterItemAll()
        {
            return DataAccess.SelectAllDataSet<RepRegisterItemEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<RepRegisterItemEntity> GetRepRegisterItemAllList()
        {
            return DataAccess.SelectAll<RepRegisterItemEntity>();
        }
        #endregion

        #region Functions
        public static RepRegisterItemEntity GetRepRegisterItemByID(string ID)
        {
            if(string.IsNullOrEmpty(ID))
            return null;
            RepRegisterItemEntity m=new RepRegisterItemEntity();
            m.RegisterItemId=ID;
            return DataAccess.SelectSingle<RepRegisterItemEntity>(m);
        }

        public static DataTable GetDtRegisterItemByRegisterID(string RegisterID)
        {
            if (string.IsNullOrEmpty(RegisterID))
                return null;
            string Sql = @"SELECT RRI.*,MP.PRODUCT_CODE,PRODUCT_NAME FROM REP_REGISTER_ITEM RRI
                LEFT JOIN MST_PRODUCT MP ON RRI.PRODUCT_ID=MP.PRODUCT_ID WHERE 1=1 AND RRI.REGISTER_ID='" + RegisterID+"' ";
            DataSet ds = DataAccess.SelectDataSet(Sql);
            if (ds != null && ds.Tables[0] != null)
            {
                return ds.Tables[0];
            }
            else return null;
        }

        public static DataTable GetDtRegisterItemByCondition(string Condition)
        {
            string Sql = @"SELECT RRI.*,MP.PRODUCT_CODE,PRODUCT_NAME,MCC.CONTACT_NAME,RRA.FILE_NAME
                FROM REP_REGISTER_ITEM RRI
                LEFT JOIN MST_PRODUCT MP ON RRI.PRODUCT_ID=MP.PRODUCT_ID 
                LEFT JOIN MST_CUSTOMER_CONTACT MCC ON RRI.CONTACT_ID=MCC.CONTACT_ID 
                LEFT JOIN REP_REGISTER_ATTACHED RRA ON RRI.REGISTER_ITEM_ID=RRA.REGISTER_ITEM_ID
                WHERE 1=1 ";
            if (!string.IsNullOrEmpty(Condition))
            {
                Sql += Condition;
            }
            DataSet ds = DataAccess.SelectDataSet(Sql);
            if (ds != null && ds.Tables[0] != null)
            {
                return ds.Tables[0];
            }
            else
            {
                return null;
            }
        }
        #endregion
    }
	
	
}	

